package com.xidian.GMS.service.impl;

import java.text.ParseException;
import java.util.Date;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xidian.GMS.dto.Page;

import com.xidian.GMS.entity.JobFair;
import com.xidian.GMS.entity.RelevantEnterprisesWebsite;
import com.xidian.GMS.mapper.JobFairMapper;
import com.xidian.GMS.mapper.RelevantEnterprisesWebsiteMapper;
import com.xidian.GMS.service.RelevantEnterprisesWebsiteService;
@Service
public class RelevantEnterprisesWebsiteServiceImpl implements RelevantEnterprisesWebsiteService {
	@Autowired
	private RelevantEnterprisesWebsiteMapper relevantEnterprisesWebsiteMapper;
	@Override
	public RelevantEnterprisesWebsite Insert(RelevantEnterprisesWebsite relevantEnterprisesWebsite) {
	
	   	  int rows = relevantEnterprisesWebsiteMapper.insert(relevantEnterprisesWebsite);
			if( relevantEnterprisesWebsite == null ||rows == 0){
				throw new RuntimeException("错误");
			}
	          return relevantEnterprisesWebsite;
	    }

	@Override
	public boolean delete(int websiteid) {
	      int x =  relevantEnterprisesWebsiteMapper.deleteByPrimaryKey(websiteid);
	  	  if (x == 1) {
	  	  	  return true;
		}
	          return false;
	}

	@Override
	public boolean update(int websiteid, String websitename, String websiteaddress) {
	  {
			// TODO Auto-generated method stub
			RelevantEnterprisesWebsite relevantEnterprisesWebsite = relevantEnterprisesWebsiteMapper.selectByPrimaryKey(websiteid);
				
			    relevantEnterprisesWebsite.setWebsitename(websitename);
		    	relevantEnterprisesWebsite.setWebsiteaddress(websiteaddress);
	        int temp = relevantEnterprisesWebsiteMapper.updateByPrimaryKeySelective(relevantEnterprisesWebsite);
			
	    	  if (temp == 1) {
	   	  	  return true;
	 	}
	           return false;
	     }
	}

	@Override
	public Page getRelevantEnterprisesWebsite(int cur) {
		Page page = new Page(cur);
		
		int count = relevantEnterprisesWebsiteMapper.count();
		
		List<RelevantEnterprisesWebsite> accounts = relevantEnterprisesWebsiteMapper.findAll(page.getOffset(), page.getSize());
		
		page.setCount(count);
		page.setList(accounts);
		
		return page;
	}

}

